﻿using UnityEngine;
using FairyGUI;

public class FBiology : GButton
{
    GLoader _loader;
    Biology _biologyData;
    GLabel _discriptLabel;
    GLabel _nameLabel;

    public override void ConstructFromXML(FairyGUI.Utils.XML cxml)
    {
        base.ConstructFromXML(cxml);

        _loader = ((GComponent)this.GetChild("card")).GetChild("imgCom").asCom.GetChild("img").asLoader;
        _discriptLabel = this.GetChild("discriptLabel").asLabel;
        _nameLabel = this.GetChild("nameLabel").asLabel;
    }

    public void InitData(Biology biologyData,bool isShowClickAni = true)
    {
        if (!isShowClickAni) _loader.parent.touchable = false;
        else _loader.parent.touchable = true;
        _biologyData = biologyData;
        Fresh();
    }

    public void Fresh()
    {
        if (_biologyData == null) return;
        _loader.url = _biologyData.img;

        var name = _biologyData.GetBiologyName();
        if (_nameLabel.text != name) _nameLabel.text = name;
        //默认展示1级
        var discript = _biologyData.GetBiologyDescript();
        if (_discriptLabel.text != discript) _discriptLabel.text = discript;
    }

    public void SetImg(string url)
    {
        _loader.url = url;
    }

    public string GetBiologyImg()
    {
        return _loader.url;
    }
}

